﻿using System;
using System.Security.Principal;
using System.Windows.Forms;
using Bizspoke.BizTalk.Adapter;

namespace Bizspoke.BizTalk.HATPlugIn
{
    internal class UserRole
    {
        private static string _BizTalkServerAdministratorGroup;

        public static bool IsBizTalkServerAdministrator()
        {
            WindowsPrincipal principal = new WindowsPrincipal(WindowsIdentity.GetCurrent());
            return principal.IsInRole(BizTalkServerAdministratorGroup);
        }

        public static string BizTalkServerAdministratorGroup
        {
            get
            {
                if (_BizTalkServerAdministratorGroup == null)
                {
                    _BizTalkServerAdministratorGroup = Info.BizTalkAdminNTGroup;
                    if (-1 == _BizTalkServerAdministratorGroup.LastIndexOf('\\'))
                    {
                        _BizTalkServerAdministratorGroup = SystemInformation.ComputerName + @"\" + _BizTalkServerAdministratorGroup;
                    }
                }
                return _BizTalkServerAdministratorGroup;
            }
        }
    }
}

